package com.mocha.activeMq;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.Produce;


public class AppCustomer1 {
	//地址
	public static final String URL = "tcp://localhost:61616";
	public static final String queueName = "quene-test";
	public static void main(String[] args) throws JMSException {
		//1、创建工厂
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(URL);
		//2.创建连接
		Connection connection = connectionFactory.createConnection();
		//3.启动连接
		connection.start();
		//4.建立会话false 不启动事务
		Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
		//5.创建目的地
		Destination destination = session.createQueue(queueName);
		//6.创建生产者
		MessageConsumer consumer  = session.createConsumer(destination);
		consumer.setMessageListener(new MessageListener() {
			
			@Override
			public void onMessage(Message message) {
				// TODO Auto-generated method stub
				TextMessage msg = (TextMessage)message;
				try {
					System.out.println("消费者1收到消息:"+msg.getText());
				} catch (JMSException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		
	}
}
